<template>
  <transition-group
    enter-active-class="animate__animated animate__lightSpeedInLeft"
    appear
    tag="div"
    class="login"
  >
    <div class="login-left" v-if="flag">
      <div class="login-left-box1">
        <h1>已有账号?</h1>
        <div>请使用你的账号进行登录</div>
        <el-button @click="registe">登录</el-button>
      </div>
      <div class="login-left-box2">
        <h1>注册</h1>
        <el-form
          :model="regisForm"
          :rules="registRules"
          ref="registeRuleFormRef"
        >
          <el-form-item prop="userName">
            <el-input v-model="regisForm.userName" placeholder="用户名" />
          </el-form-item>
          <el-form-item prop="userPass">
            <el-input
              v-model="regisForm.userPass"
              placeholder="密码"
              type="password"
            />
          </el-form-item>
          <el-form-item prop="userSex">
            <el-radio-group v-model="regisForm.userSex">
              <el-radio label="男" />
              <el-radio label="女" />
            </el-radio-group>
          </el-form-item>
          <el-form-item prop="birthday">
            <el-date-picker
              type="date"
              v-model="regisForm.birthday"
              placeholder="出生年龄"
            />
          </el-form-item>
          <el-form-item prop="phone">
            <el-input v-model="regisForm.phone" placeholder="手机号" />
          </el-form-item>
          <el-form-item prop="address">
            <el-input v-model="regisForm.address" placeholder="居住地址" />
          </el-form-item>
          <div class="registe" @click="subRegiste(registeRuleFormRef)">
            <el-button>注册</el-button>
          </div>
        </el-form>
      </div>
    </div>

    <div class="login-right" v-else>
      <div class="login-right-box1">
        <h1>登录</h1>
        <el-form
          :model="loginForm"
          ref="loginRuleFormRef"
          :rules="loginRules"
          @keydown.enter="onSubmit(loginRuleFormRef)"
        >
          <el-form-item prop="userName">
            <el-input v-model="loginForm.userName" placeholder="账号" />
          </el-form-item>
          <el-form-item prop="userPass">
            <el-input
              type="password"
              v-model="loginForm.userPass"
              placeholder="密码"
            />
          </el-form-item>

          <div class="forget">忘记密码?</div>

          <el-form-item>
            <div class="btn-box">
              <el-button @click="onSubmit(loginRuleFormRef)">登录</el-button>
              <el-button @click="gohome">返回</el-button>
            </div>
          </el-form-item>
        </el-form>
      </div>
      <div class="login-right-box2">
        <h1>没有账号?</h1>
        <div class="text">立即加入我们，和我们一起开始旅程吧</div>
        <el-button @click="registe">注册</el-button>
      </div>
    </div>
  </transition-group>
</template>

<script lang="ts" setup>
import "animate.css";
import { useLogin } from "@/hooks/loginForm/useLogin";
import { useRegist } from "@/hooks/loginForm/useRegist";
//登录hooks
const { router, loginForm, loginRuleFormRef, loginRules, onSubmit } =
  useLogin();
// 注册hooks
const { registeRuleFormRef, registRules, regisForm, subRegiste, flag } =
  useRegist();
// 返回未登录的首页
const gohome = () => {
  router.push("/userhome");
};
//切换登录与注册框
const registe = () => {
  flag.value = !flag.value;
};

</script>

<style lang="less" scoped>
.login {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 50%;
  height: 90%;
  transform: translate(-50%, -50%);
  border-radius: 10px;
  box-shadow: 0px 0px 8px 8px rgb(180, 174, 174);
  display: grid;
  background: url("@/assets/img/back.webp");
  background-size: 100% 100%;
  z-index: 1;
  overflow: hidden;
  &-left {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    &-box1 {
      background-color: transparent;
      color: #000;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      div {
        margin: 10px 0;
      }
      .el-button {
        background-color: transparent;
        padding: 0 30px;
        border-radius: 50px;
        color: #000;
      }
    }
    &-box2 {
      background-color: #fff;
      border-radius: 10px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      .registe {
        text-align: center;
        .el-button {
          padding: 0 30px;
          border-radius: 50px;
          background-color: #18364a;
          color: #fff;
        }
      }
    }
  }
  &-right {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    &-box1 {
      background-color: #fff;
      border-radius: 10px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      h1 {
        margin: 20px 0;
      }
      .forget {
        text-align: center;
        margin-bottom: 10px;
        font-size: 12px;
      }
      .forget:hover {
        cursor: pointer;
      }
      .btn-box {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-around;
        .el-button {
          color: #fff;
          background-color: #18364a;
          border-radius: 50px;
          padding: 0 20px;
        }
      }
    }
    &-box2 {
      background-color: transparent;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      color: #fff;
      .text {
        margin: 10px 0;
      }
      .el-button {
        background-color: transparent;
        color: #fff;
        padding: 0 40px;
        border-radius: 50px;
      }
    }
  }
}
</style>
